package com.arcvideo.acsconnect.app;

import com.framework.core.utils.SPUtil;

/**
 * @author shenmengchao
 * @version 1.0.0
 * @date 2017/8/4
 * @description
 */

public class SettingDataCenter {

    public final static String KEY_FRAME_WIDTH = "KEY_FRAME_WIDTH";
    public final static String KEY_FRAME_HEIGHT = "KEY_FRAME_HEIGHT";
    public final static String KEY_FPS = "KEY_FPS";
    public final static String KEY_CODE_RATE = "KEY_CODE_RATE";
    public final static String KEY_AUDIO_RATE = "KEY_AUDIO_RATE";
    public final static String KEY_SOURCE_TYPE = "KEY_SOURCE_TYPE";
    public final static String KEY_AUDIO_TYPE = "KEY_AUDIO_TYPE";

    public static SettingDataCenter mInstance;
    private int mFrameWidth = ResolutionEnum.P720.getWidth();
    private int mFrameHeight = ResolutionEnum.P720.getHeight();
    private int mFps = 24;
    private int mCodeRate = CodeRateEnum.P720.getDefaultRate();
    private int mAudioRate = 44;
    private int mSourceType = 2; //  1 == phone camera, 2 == usb camera


    private SettingDataCenter() {

    }

    public void init() {
        if (0 == getFps()) {
            setFps(30);
        }
        if (0 == getCodeRate()) {
            setCodeRate(CodeRateEnum.P720.getDefaultRate());
        }
        if (0 == getFrameWidth()) {
            setFrameWidth(ResolutionEnum.P720.getWidth());
        }
        if (0 == getFrameHeight()) {
            setFrameHeight(ResolutionEnum.P720.getHeight());
        }
    }

    public static SettingDataCenter getInstance() {
        if (null == mInstance) {
            mInstance = new SettingDataCenter();
        }
        return mInstance;
    }

    public void setFrameWidth(int frameWidth) {
        mFrameWidth = frameWidth;
        SPUtil.put(AcsConnectApplication.getInstance(), KEY_FRAME_WIDTH, frameWidth);
    }

    public int getFrameWidth() {
        int frameWidth = SPUtil.getInt(AcsConnectApplication.getInstance(), KEY_FRAME_WIDTH);
        if (0 != frameWidth) {
            mFrameWidth = frameWidth;
        }
        return mFrameWidth;
    }

    public void setFrameHeight(int frameWidth) {
        mFrameWidth = frameWidth;
        SPUtil.put(AcsConnectApplication.getInstance(), KEY_FRAME_HEIGHT, frameWidth);
    }

    public int getFrameHeight() {
        int frameHeight = SPUtil.getInt(AcsConnectApplication.getInstance(), KEY_FRAME_HEIGHT);
        if (0 != frameHeight) {
            mFrameHeight = frameHeight;
        }
        return mFrameHeight;
    }

    public void setFps(int fps) {
        mFps = fps;
        SPUtil.put(AcsConnectApplication.getInstance(), KEY_FPS, fps);
    }

    public int getFps() {
        int fps = SPUtil.getInt(AcsConnectApplication.getInstance(), KEY_FPS);
        if (0 != fps) {
            mFps = fps;
        }
        return mFps;
    }

    public void setCodeRate(int codeRate) {
        mCodeRate = codeRate;
        SPUtil.put(AcsConnectApplication.getInstance(), KEY_CODE_RATE, codeRate);
    }

    public int getCodeRate() {
        int codeRate = SPUtil.getInt(AcsConnectApplication.getInstance(), KEY_CODE_RATE);
        if (0 != codeRate) {
            mCodeRate = codeRate;
        }
        return mCodeRate;
    }

    public void setAudioRate(int audioRate) {
        mAudioRate = audioRate;
        SPUtil.put(AcsConnectApplication.getInstance(), KEY_AUDIO_RATE, audioRate);
    }

    public int getAudioRate() {
        int audioRate = SPUtil.getInt(AcsConnectApplication.getInstance(), KEY_AUDIO_RATE);
        if (0 != audioRate) {
            mAudioRate = audioRate;
        }
        return mAudioRate;
    }

    public void setSourceType(int type) {
        mSourceType = type;
        SPUtil.put(AcsConnectApplication.getInstance(), KEY_SOURCE_TYPE, type);
    }

    public int getSourceType() {
        int type = SPUtil.getInt(AcsConnectApplication.getInstance(), KEY_SOURCE_TYPE);
        if (0 != type) {
            mSourceType = type;
        }
        return mSourceType;
    }

    public void setAudioType(int audioType){
        SPUtil.put(AcsConnectApplication.getInstance(), KEY_AUDIO_TYPE, audioType);
    }

    public int getAudioType(){
        return SPUtil.getInt(AcsConnectApplication.getInstance(), KEY_AUDIO_TYPE);
    }
}
